<template>
  <div>
    <Navbar :appTitle="appTitle" @ClickRight="ClickRight" />
    <div
      class="form-content wrap-apply"
      style="margin-right: 30px;"
      :style="{
        top: GLOBAL.currentEnvironment ? '0' : '',
        height: GLOBAL.currentEnvironment ? '100vh' : 'calc(100vh - 100px)',
        paddingBottom: GLOBAL.currentEnvironment ? '120px' : '',
      }"
    >
      <van-cell-group>
        <van-cell center>
          <template #title>
            <p class=" ">
              <span
                style="font-size: 0.16rem;
          font-family: PingFang SC;
          font-weight: 500;
          color: #191f25;
          margin-bottom: 0.16rem;"
                >{{ detailInfo.taskCode || "-" }}</span
              >
            </p>
            <p
              class=""
              style="justify-content: space-between;
          margin-bottom: 0.23rem;color: #888888;"
            >
              <span></span>业务类型 : {{ detailInfo.typeText || "-" }}
            </p>
            <p
              class=""
              style="justify-content: space-between;
          margin-bottom: 0.23rem;color: #888888;"
            >
              <span></span>客户 : {{ detailInfo.customerName || "-" }}
            </p>
          </template>
          <!-- 使用默认插槽自定义内容 -->
          <template #default>
            <p class="" style="color:#fe9400;font-size:0.33rem">
              <span></span>待下发拣货:{{ detailInfo.typeText || "-" }}
            </p>
            <p
              class=""
              style="color:#4bd863;font-size:0.33rem"
              @click="GoReceiptedGoods(item)"
            >
              已下发拣货:{{ detailInfo.customerName || "-" }}
            </p>
          </template>
        </van-cell>

        <div class="bottomLine" style="height:8px"></div>
        <van-cell>
          <template #title>
            <p class="label  FormTit" style="font-size:0.33rem">
              <span></span>拣货员
            </p>
          </template>
          <!-- 使用默认插槽自定义内容 -->
          <template #default>
            <div class="">
              <van-field-select-picker
                style="height:44px"
                input-align="right"
                :supportClear="true"
                label=""
                placeholder="请选择"
                v-model="buildForm.picker"
                :columns="warehousingTypes"
                :option="{ label: 'text', value: 'value' }"
                @confirm="(itemReport) => selectReport(itemReport, 'picker')"
              />
            </div>
          </template>
        </van-cell>
        <div class="bottomLine" style="height:3px"></div>
        <div>
          <div class="tabs-box" :class="{ 'tabs-box-rel': tabsConfig.all }">
            <div class="tabs-up">
              <div class="tabs">
                <div
                  class="tab"
                  :class="{ active: tabsConfig.showIndex == index }"
                  v-for="(item, index) in 6"
                  v-if="(index < 3 && !tabsConfig.all) || tabsConfig.all"
                  @click="tabsConfig.showIndex = index"
                  style="font-size: 0.38rem;"
                >
                  测试
                </div>
                <div
                  class="tab tabsAll"
                  v-if="!tabsConfig.all"
                  @click="tabsConfig.all = true"
                  style="font-size: 0.38rem;"
                >
                  全部<van-icon name="arrow-down" />
                </div>
              </div>
              <div
                class="arrow-up-tab tabsAll"
                v-if="tabsConfig.all"
                @click="tabsConfig.all = false"
                style="font-size: 0.38rem;"
              >
                收起<van-icon name="arrow-up" />
              </div>
            </div>

            <div class="tabs" v-if="tabsConfig.all">
              <div class="tab">占位</div>
            </div>
          </div>
          <div class="bottomLine" style="height:2px"></div>

          <div>
            <div
              class="wrap"
              v-for="(p, index) in 6"
              v-if="tabsConfig.showIndex == index"
            >
              <div class="top">
                <div class="title title-m">
                  {{ p.goodsCode || "-" }} | {{ p.goodsName || "-" }}|
                  {{ p.spec || "-" }}
                </div>
              </div>
              <div class="center">
                <div>
                  <p>
                    <span class="key">产地：</span>
                    <span class="value">{{ p.address || "-" }}</span>
                  </p>
                  <p>
                    <span class="key">包装规格：</span>
                    <span class="value">{{ p.packageSpec || "-" }}</span>
                  </p>
                  <p>
                    <span class="key">待下发/ 物品数量</span>
                    <span class="value">{{ p.unitName || "-" }}</span>
                  </p>
                </div>
              </div>
              <div class="label" style="padding:0 0.42667rem ">
                <span>fdfdfd</span>
              </div>
            </div>
          </div>
        </div>
      </van-cell-group>

      <van-cell-group
        v-for="(p, i) in entryDetails"
        :key="i + '_' + p.serialId"
        style="margin-top: 5px;"
      >
        <p
          class="label otherText"
          style="display: flex; justify-content: space-between"
        >
          库位{{ i + 1 }}）<span
            style="font-weight: 400; color:rgb(196, 196, 196);margin-right: 20px"
            @click="deleteGoods(i)"
            v-if="entryDetails.length > 0"
            >删除</span
          >
        </p>

        <van-cell>
          <template #title>
            <p class="label  FormTit"><span></span>拣货库位</p>
          </template>
          <!-- 使用默认插槽自定义内容 -->
          <template #default>
            <div class="">
              <van-field-select-picker
                :supportClear="true"
                input-align="right"
                label=""
                placeholder="请选择"
                v-model="p.goodsBatchId"
                :columns="warehousingTypes"
                :option="{ label: 'itemText', value: 'itemValue' }"
                @confirm="inWarehouseTypeConfirm"
              />
            </div>
          </template>
        </van-cell>
        <div class="bottomLine"></div>
        <van-cell>
          <template #title>
            <p class="label  FormTit"><span></span>拣货批号</p>
          </template>
          <!-- 使用默认插槽自定义内容 -->
          <template #default>
            <div class="">
              <van-field
                input-align="right"
                v-model="p.outboundGoodsNum"
                :maxLength="21"
                placeholder="请输入"
                @blur="checkInputValue(buildForm.goodsCode)"
              />
            </div>
          </template>
        </van-cell>
        <div class="bottomLine"></div>
        <van-cell>
          <template #title>
            <p class="label   FormTit"><span></span>拣货数量</p>
          </template>
          <!-- 使用默认插槽自定义内容 -->
          <template #default>
            <div class="">
              <van-field
                input-align="right"
                v-model="p.outboundGoodsNum"
                :maxLength="21"
                placeholder="请输入"
                @blur="checkInputValue(buildForm.goodsCode)"
              />
            </div>
          </template>
        </van-cell>
        <div class="bottomLine"></div>

        <div class="bottomLine"></div>
        <div
          v-if="goodsTypeExtendedFields && goodsTypeExtendedFields.length != 0"
        >
          <div v-for="(p2, index2) in goodsTypeExtendedFields" :key="index2">
            <p class="label FormTit" :class="{ required: p2.fieldMust == 2 }">
              <span></span>{{ p2.fieldName }}
            </p>
            <van-field
              :placeholder="p2.placeholder"
              input-align="right"
              v-model="p[p2.fieldKey]"
              :readonly="p2.fieldMust == 1"
              :type="p2.fieldType == 3 ? 'number' : 'input'"
              :maxlength="p2.fieldLength || '-'"
              :formatter="(value) => clearNoNumTwo(value, p2.fieldType)"
            />
            <div class="bottomLine"></div>
          </div>
        </div>
      </van-cell-group>
      <div class="addGoodScontain">
        <div class="addgoods" @click="addInventoryGoods">
          <van-icon name="plus" size="16px" color="#1890ff" style="top: 2px" />
          <a>物品</a>
        </div>
        <!-- <div class="addgoods">
          <scanInputGoods ref="scanGoodsInput" @changeScan="changeScan" />
        </div> -->
      </div>

      <div class="search-bottoms">
        <span class="btnconfirm" @click="btnConfirm">提交</span>
      </div>
    </div>
    <!--选择领出人 -->
    <!-- <ContactPickers
      :key="'receiverPersion'"
      :visible="selectShow"
      ref="mychild"
      :max="1"
      @closePicker="selectShow = false"
      @confirm="confirmReceiverPersion"
    /> -->
    <!--选择出库日期 -->
    <van-popup v-model="timePickShow" position="bottom">
      <van-datetime-picker
        @confirm="confirmPick"
        v-model="happenTime"
        @cancel="cancelPick"
        type="date"
        title="生产日期"
        :formatter="formatter"
      />
    </van-popup>
    <!--选择物品 -->
    <goods-pickers
      v-if="showGoodsPicker"
      :listUrl="listUrl"
      :columns="goodsColumns"
      :selectedGoods="entryDetails"
      @getCheckedGoods="getCheckedGoods"
    ></goods-pickers>
    <!--销售订单 -->
    <!-- <saleOrder-pickers
      v-if="showSaleOrderPickers"
      :listUrl="saleOrderPickerslistUrl"
      :columns="saleOrderColumns"
      :selectedProduceOrder="selectedSaleOrder"
      @getCheckedProduceOrder="getCheckedSaleOrder"
    ></saleOrder-pickers> -->
    <!--生产工单 -->
    <!-- <produceOrder-pickers
      v-if="showProduceOrderPickers"
      :listUrl="produceOrderlistUrl"
      :columns="produceOrderColumns"
      :selectedProduceOrder="selectedProduceOrder"
      @getCheckedProduceOrder="getCheckedProduceOrder"
    ></produceOrder-pickers> -->
    <!--销售订单 -->
  </div>
</template>
<script>
import { clearNoNum } from "@/utils/util";
import { getAction } from "@/api/manage";
import moment from "moment";
import Navbar from "@/components/navBar/navBar_right";
import {
  outboundOrderTypeList,
  // formTypeExtendedFieldList,
  outboundOrderAdd,
  outboundOrderEdit,
  outboundOrderDetail,
  inventoryOrderDetailList,
} from "@/api/mobile";
import VanFieldSelectPicker from "@/components/ActionSheet/VanFieldSelectPicker";
import ContactPickers from "@/components/choiceuse/ContactPickers";
import GoodsPickers from "@/components/choiceuse/GoodsPickers";
import saleOrderPickers from "@/components/choiceuse/saleOrderPickers";
import store from "@/store";
import scanInputGoods from "@/components/scanCode/scanInputGoods";
import produceOrderPickers from "@/components/choiceuse/produceOrderPickers";
import { APILX } from "@/api/requestLx";
import { workOrderList } from "@/api/productionApply";
import { getDictItemsByTypes } from "@/api/inventoryOrder";
export default {
  name: "inventoryOrderForm",
  components: {
    Navbar,
    VanFieldSelectPicker,
    ContactPickers,
    GoodsPickers,
    scanInputGoods,
    saleOrderPickers,
    produceOrderPickers,
  },
  data() {
    return {
      tabsConfig: {
        all: false,
        showIndex: 0,
      },
      detailInfo: {},
      activeIndex: 0,
      examKey: 1,
      //辅助单位
      buildForm: {
        entryCode: "",
        types: "SALE",
        produceOrderId: "",
        produceOrderName: "",
        saleOrderId: "",
        saleOrderName: "",
        receiverPersion: "",
        receiverPersionName: "",
        outWarehouseTime: "",
        extDataJson: {},
      },

      timePickShow: false,
      recentGoodsIndex: 0,
      entryDetails: [],
      happenTime: new Date(),
      appTitle: "下发拣货",
      isEdit: false,
      parentId: "",
      showExam: true,
      warehousingTypes: [],
      selectShow: false,
      timePickShow: false,
      formTypeExtendedFields: [],
      goodsTypeExtendedFields: [],
      showGoodsPicker: false,
      listUrl: "/wmsgoodsnotification/getOutboundTaskNotification",
      goodsColumns: {
        titleKey: ["goodsCode", "goodsName", "spec"], //标题
        content: [
          //内容
          {
            name: "产地",
            key: ["address"],
          },
          {
            name: "包装规格",
            key: ["packageSpec"],
          },
          {
            name: "基本单位",
            key: ["unitName"],
          },
        ],
        // labelKey: ["updateTime", "serialSpecifications"], //标签
        operationText: "",
      },

      showSaleOrderPickers: false,
      // saleOrderPickerslistUrl: "/sale/saleOrderInfo/list",
      // saleOrderColumns: {
      //   titleKey: "orderCode", //标题
      //   content: [
      //     //内容
      //     {
      //       name: "客户",
      //       key: ["customName"],
      //     },
      //     {
      //       name: "物品种类",
      //       key: ["serialInfoCount"],
      //     },
      //     {
      //       name: "工单数",
      //       key: ["produceInfoCount"],
      //     },
      //   ],
      //   operationText: "",
      // },
      selectedSaleOrder: [],

      showProduceOrderPickers: false,
      // produceOrderlistUrl: "/produceorder/produceOrderInfo/list",
      // produceOrderColumns: {
      //   titleKey: "orderCode", //标题
      //   content: [
      //     //内容
      //     {
      //       name: "生产物品",
      //       key: ["serialName"],
      //     },
      //     {
      //       name: "计划时间",
      //       key: ["timePeriod"],
      //     },
      //     {
      //       name: "计划生产数量",
      //       key: ["planProduceNum"],
      //     },
      //   ],
      //   labelKey: ["orderStatusText"], //标签
      //   operationText: "",
      // },
      selectedProduceOrder: [],
    };
  },
  beforeRouteLeave(to, from, next) {
    if (this.showPeopleSlect) {
      this.$refs.examine.closePicker();
      next(false);
    } else if (
      this.showGoodsPicker ||
      this.showProduceOrderPickers ||
      this.showSaleOrderPickers
    ) {
      this.showGoodsPicker = false;
      this.showProduceOrderPickers = false;
      this.showSaleOrderPickers = false;
      this.appTitle = this.isEdit ? "编辑出库任务" : "新建出库任务";
      next(false);
    } else {
      next();
    }
  },
  async created() {
    let _this = this;
    getDictItemsByTypes({ type: 4 }).then((res) => {
      if (res.code == 200 && res.result) {
        _this.warehousingTypes = res.result;
        console.log("类型", _this.warehousingTypes);
      }
    });
    // 扫工单码进入
    if (
      this.$route.query.formPage == "scanCode" &&
      this.$route.query.code.EntityType == "workOrder"
    ) {
      let itemRes = await workOrderList({ id: this.$route.query.code.id });
      this.getCheckedProduceOrder(itemRes.result.records);
    }
    // 扫物品码进入
    if (
      this.$route.query.formPage == "scanCode" &&
      this.$route.query.code.EntityType == "goods"
    ) {
      this.changeScan(this.$route.query, "scan");
    }

    store.commit("SET_CURRENT_PREFIX", "/jksaas-produce/produce");
    if (this.$route.query.id) {
      this.isEdit = true;
      this.parentId = this.$route.query.id;
    } else {
      this.isEdit = false;
      this.parentId = "";
    }
    this.buildForm.outWarehouseTime = moment(this.happenTime).format(
      "YYYY-MM-DD HH:mm"
    );
    let currentLoginUser = JSON.parse(
      localStorage.getItem("pro__Login_Userinfo")
    ).value;
    console.log("currentLoginUser", currentLoginUser);
    this.buildForm.receiverPersion = currentLoginUser.id;
    this.buildForm.receiverPersionName = currentLoginUser.realname;
    if (this.parentId) {
      this.appTitle = "编辑出库任务";
      // 出库单表单详情
      outboundOrderDetail({ id: this.parentId }).then((res) => {
        if (res.code == 200) {
          let resObj = res.result;
          for (let k in this.buildForm) {
            this.buildForm[k] = resObj[k];
            if (resObj.orderCode) {
              this.buildForm.saleOrderName = resObj.orderCode;
            }
          }
        }
      });
      // 出库单关联物品详情
      inventoryOrderDetailList({ entryId: this.parentId, inOutType: 1 }).then(
        (res) => {
          if (res.code == 200 && res.result) {
            this.entryDetails = res.result.records.map((son) => {
              return {
                serialId: son.serialId,
                serialLongName: son.serialName + "|" + son.serialNumber,
                serialName: son.serialName || "-",
                serialNumber: son.serialNumber || "-",
                serialSpecifications: son.serialSpecifications || "-",
                serialUnit: son.unitName || "-",
                inWarehouseNum: son.inWarehouseNum || null,
                ...son.extDataJson,
              };
            });
          }
        }
      );
    }
    this.initData();
  },
  methods: {
    //已下发拣货跳转
    // GoReceiptedGoods(e) {
    //   this.$router.push({
    //     path: "/",
    //     query: {
    //       id: e.id,
    //     },
    //   });
    // },
    // 物品明细-》删除
    deleteGoods(i) {
      this.entryDetails.splice(i, 1);
    },
    //出库类型选择
    selectReport(itemReport, key) {
      if (itemReport) {
        this.buildForm[key] = itemReport.value;
      } else {
        this.buildForm[key] = "";
      }
    },
    // 打开选择时间
    openTimePicker(index, value) {
      this.timePickShow = true;
      this.recentGoodsIndex = index;
      if (value) {
        this.happenTime = value;
      } else {
        this.happenTime = "";
      }
    },
    // 出库类型 清空 生产订单 销售订单相关字段
    inWarehouseTypeConfirm(data1, index, data2) {
      if (data1) {
        let that = this;
        if (that.buildForm.outWarehouseType != data2) {
          this.buildForm.produceOrderId = "";
          this.buildForm.produceOrderName = "";

          this.buildForm.saleOrderId = "";
          this.buildForm.saleOrderName = "";

          this.entryDetails = [{}];
          this.$forceUpdate();
        }
      }
    },
    // 自定义字段格式化
    clearNoNumTwo(value, type) {
      if (type != 3) {
        return value;
      } else {
        return value.replace(/[^\d]/g, "");
      }
    },
    // 提交 - 表单验证
    btnConfirm() {
      if (!this.buildForm.taskCode) {
        this.$toast(`请输入任务编号`);
        return;
      }
      if (!this.buildForm.types) {
        this.$toast(`请选择业务类型`);
        return;
      }

      try {
        // 出库物品明细 为空 选项名称、数量 表单验证
        if (this.entryDetails && this.entryDetails.length > 0) {
          this.entryDetails.forEach((element, index) => {
            if (element.id) {
              if (!element.outboundGoodsNum || element.outboundGoodsNum == "") {
                throw new Error(`物品明细（${index + 1}）数量不可为空`);

                this.$toast(`出库任务物品明细（${index + 1}）数量不可为空`);
                return;
              }
            } else {
              throw new Error(`请选择物品1`);

              this.$toast(`请选择出库物品`);
              return;
            }
          });
        } else {
          throw new Error(`请选择物品2`);

          this.$toast(`请选择出库物品`);
          return;
        }
      } catch (error) {
        this.$toast(error.message);
        return false;
      }

      this.handleSubmit();
    },
    handleSubmit() {
      let params = {
        ...this.buildForm,
        entryDetails: this.entryDetails.map((ele) => {
          let { serialId, inWarehouseNum } = ele;
          let extDataJson = {};

          this.goodsTypeExtendedFields.forEach((item) => {
            extDataJson[item.fieldKey] = ele[item.fieldKey];
          });

          return {
            serialId: serialId,
            inWarehouseNum: inWarehouseNum,
            extDataJson: extDataJson,
          };
        }),
      };

      let commitApi = "";
      let successMeg = "";
      if (this.parentId) {
        params.id = this.parentId;
        commitApi = outboundOrderEdit;
        successMeg = "出库单编辑成功！";
      } else {
        commitApi = outboundOrderAdd;
        successMeg = "出库单创建成功！";
      }

      commitApi(params).then((res) => {
        if (res.success) {
          this.$toast(successMeg);
          this.$router.go(-1);
        } else {
          this.$toast(res.message);
        }
      });
    },
    // 初始化页面数据
    initData() {
      // 获取出库类型
      // outboundOrderTypeList().then((res) => {
      //   if (res.code == 200 && res.result) {
      //     this.warehousingTypes = res.result;
      //   }
      // });
      // 获取出出库 自定义表单字段;
      // formTypeExtendedFieldList({ formType: 5 }).then((res) => {
      //   if (res.code == 200 && res.result) {
      //     this.formTypeExtendedFields = res.result;
      //   }
      // });
      // 获取出库单关联物品 自定义表单字段;
      // formTypeExtendedFieldList({ formType: 6 }).then((res) => {
      //   if (res.code == 200 && res.result) {
      //     this.goodsTypeExtendedFields = res.result;
      //   }
      // });
    },
    // 领出人删除
    // confirmDdtjr() {
    //   this.buildForm.receiverPersion = "";
    //   this.buildForm.receiverPersionName = "";
    // },
    // 领出人选中
    // confirmReceiverPersion(id, items) {
    //   if (!id) {
    //     this.confirmDdtjr();
    //   } else {
    //     this.buildForm.receiverPersion = id;
    //     this.buildForm.receiverPersionName = items[0].realname;
    //   }
    //   this.selectShow = false;
    // },
    // 确定选择时间
    confirmPick(date) {
      this.buildForm.outWarehouseTime = moment(date).format("YYYY-MM-DD HH:mm");
      this.entryDetails[this.recentGoodsIndex].produceDate = moment(
        date
      ).format("YYYY-MM-DD");

      this.timePickShow = false;
    },
    // 取消选择时间
    cancelPick() {
      this.timePickShow = false;
    },
    formatter(type, val) {
      if (type === "year") {
        return val + "年";
      }
      if (type === "month") {
        return val + "月";
      }
      if (type === "day") {
        return val + "日";
      }
      if (type === "hour") {
        return val + "时";
      }
      if (type === "minute") {
        return val + "分";
      }
      return val;
    },
    // 出库物品明细-》添加
    addInventoryGoods() {
      this.appTitle = "选择物品";
      this.showGoodsPicker = true;
    },
    // 出库物品明细-》物品弹出层
    // projectVisible() {
    //   this.appTitle = "出库物品选择";
    //   this.showGoodsPicker = true;
    // },
    // 确认选中物品
    async getCheckedGoods(list) {
      this.showGoodsPicker = false;
      this.appTitle = this.isEdit ? "编辑出库任务" : "新建出库任务";

      this.entryDetails = list.map((son) => {
        let recIndex = this.entryDetails.findIndex(
          (ele) => ele.serialId == son.id
        );

        let extData = {};
        if (son.extDataJson) {
          extData = son.extDataJson;
        }

        if (recIndex != -1) {
          let recObj = this.entryDetails[recIndex];
          return recObj;
        } else {
          return {
            serialId: son.id,
            serialLongName: son.serialNumber + "|" + son.serialName,
            serialName: son.serialName || "-",
            serialNumber: son.serialNumber || "-",
            serialSpecifications: son.serialSpecifications || "-",
            serialUnit: son.unitName || "-",
            inWarehouseNum: null,
            ...extData,
          };
        }
      });
    },
    // 扫码获取物品
    changeScan(v, opratorType) {
      if (opratorType == "scan") {
        if (v.code.EntityType !== "goods") {
          this.$toast("请扫正确二维码");
          return;
        }

        getAction("/basicserial/basicSerialInfo/queryById", {
          id: v.code.id,
        }).then((res) => {
          if (res.code == 200 && res.result) {
            let ids = this.entryDetails.map((item) => item.serialId);
            if (ids.includes(res.result.id)) {
              this.$toast("该物品已存在");
              return;
            } else {
              let {
                id,
                serialName,
                serialNumber,
                serialSpecifications,
                unitName,
              } = res.result;
              let newGoods = {
                serialId: id,
                serialLongName: serialName + "|" + serialNumber,
                serialName: serialName || "-",
                serialNumber: serialNumber || "-",
                serialSpecifications: serialSpecifications || "-",
                serialUnit: unitName || "-",
                inWarehouseNum: null,
              };
              if (this.entryDetails && this.entryDetails.length == 1) {
                if (!this.entryDetails[0].serialId) {
                  this.entryDetails = [];
                  this.entryDetails.push(newGoods);
                } else {
                  this.entryDetails.push(newGoods);
                }
              } else {
                this.entryDetails.push(newGoods);
              }
              this.$forceUpdate();
            }
            // for (const goods of this.entryDetails) {
            // if (goods.serialId == res.result.id) {
            //   this.$toast("该物品已存在");
            //   break;
            // } else {
            // let {
            //   id,
            //   serialName,
            //   serialNumber,
            //   serialSpecifications,
            //   serialUnit,
            // } = res.result;
            // let newGoods = {
            //   serialId: id,
            //   serialLongName: serialName + "|" + serialNumber,
            //   serialName: serialName || "-",
            //   serialNumber: serialNumber || "-",
            //   serialSpecifications: serialSpecifications || "-",
            //   serialUnit: serialUnit || "-",
            //   inWarehouseNum: null,
            // };
            // this.entryDetails.push(newGoods);
            // this.$forceUpdate();
            // }
            // }
          }
        });
      }
    },

    // 销售订单-》添加
    addSaleOrder() {
      this.appTitle = "销售订单选择";
      this.showSaleOrderPickers = true;
    },
    // 销售订单-》删除
    deleteSaleOrder() {
      this.buildForm.saleOrderId = "";
      this.buildForm.saleOrderName = "";
      this.selectedSaleOrder = [];
    },
    // 确认选中销售订单
    async getCheckedSaleOrder(list) {
      if (!list[0].id) {
        return;
      } else {
        this.buildForm.saleOrderId = list[0].id;
        this.buildForm.saleOrderName = list[0].orderCode;
        this.selectedSaleOrder = list;
      }
      this.showSaleOrderPickers = false;
      this.appTitle = this.$route.meta.title;

      APILX.saleOrderDetail(list[0].id).then((res) => {
        if (res.code == 200) {
          if (res.result.records && res.result.records.length != 0) {
            this.entryDetails = res.result.records.map((ele) => {
              return {
                serialId: ele.bsiId,
                serialLongName: ele.serialCode + "|" + ele.serialName,
                serialName: ele.serialName || "-",
                serialNumber: ele.serialNumber || "-",
                serialSpecifications: ele.serialSpecifications || "-",
                serialUnit: ele.unitName || "-",
                inWarehouseNum: ele.serialNumber || null,
              };
            });
          }
        } else {
          this.$toast(res.message);
        }
      });
    },

    // 生产工单-》添加
    addProduceOrder() {
      this.appTitle = "生产工单选择";
      this.showProduceOrderPickers = true;
    },
    // 生产工单-》删除
    deleteProduceOrder() {
      this.buildForm.produceOrderId = "";
      this.buildForm.produceOrderName = "";
      this.selectedProduceOrder = [];
    },
    // 确认选中生产工单
    async getCheckedProduceOrder(list) {
      if (!list[0].id) {
        return;
      } else {
        this.buildForm.produceOrderId = list[0].id;
        this.buildForm.produceOrderName = list[0].orderCode;
        this.selectedProduceOrder = list;
      }
      this.showProduceOrderPickers = false;
      this.appTitle = this.$route.meta.title;

      APILX.produceOrderInfoQueryById({ id: list[0].id }).then((res) => {
        if (res.code == 200) {
          this.entryDetails = [
            ...res.result.records.map((item) => {
              let {
                serialId,
                serialName,
                serialNumber,
                serialSpecifications,
                unitName,
                planProduceNum,
                maxQualifiedNum,
              } = item;
              return {
                serialId: serialId,
                serialLongName: serialNumber + "|" + serialName,
                serialName: serialName || "-",
                serialNumber: serialNumber || "-",
                serialSpecifications: serialSpecifications || "-",
                serialUnit: unitName || "-",
                inWarehouseNum: maxQualifiedNum,
              };
            }),
          ];
        } else {
          this.$toast(res.message);
        }
      });
    },

    // 出库单 物品明细 数量处理
    needOutNumChange(e) {
      let value = clearNoNum(e);
      return value;
    },

    ClickRight() {
      this.showGoodsPicker = false;
      this.$router.push({
        path: "/application",
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/theme.scss";
@import "@/views/workManagement/materialRequisition/materialForm.scss";
.wrap-apply {
  /deep/ .van-field__control--right {
    text-align: right !important;
  }
}
.form-content {
  width: 100%;
  height: calc(100vh - 203px);
  background: #f5f5f5;
  overflow: scroll;
  padding: 20px 0;
  .label {
    padding: 0.2rem 0 0.32rem;
  }
  .formgroup {
    background: #ffffff;
    // padding: 0 0.16rem;
    margin-top: 0.1rem;
    margin-bottom: 0.2rem;
    padding-top: 0.1rem;

    .title {
      width: 0.58rem;
      height: 0.14rem;
      font-size: 0.15rem;
      font-family: PingFang SC;
      font-weight: 400;
      color: #191f25;
      line-height: 0.05rem;
      margin-left: 0.16rem;
    }
  }
  .search-bottoms {
    width: 100%;
    height: 100px;
    background: #ffffff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    bottom: 0px;
    padding: 0rem 11px;
    box-sizing: border-box;
    font-size: 32px;
    font-weight: 500;
    z-index: 9;
    .btnconfirm {
      flex: 1;
      background: #1890ff;
      box-sizing: border-box;
      height: 78px;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 6px;
      color: #ffffff;
    }
  }
}
.bottomLine {
  height: 1px;
  background-color: #f2f2f2;
  margin: 0 2px;
}
.otherText {
  font-size: 32px;
  font-weight: bold;
  color: #191f25;
  padding-left: 20px !important;
}
.haveUnitBox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  padding-right: 32px;
  /deep/ .van-cell {
    padding-right: 0;
    width: 600px;
  }
  /deep/ .van-field__control {
    max-width: 700px;
  }
}
/deep/ .van-nav-bar {
  z-index: 99;
}
/deep/.van-sidebar-item--select::before {
  color: #1890ff;
  background-color: #1890ff;
}
/deep/.van-tree-select__item--active {
  color: #1890ff;
}
.addGoodScontain {
  display: flex;
  flex-wrap: nowrap;
  .addgoods {
    flex: 1;
    background: #fff;
    font-size: 32px;
    text-align: center;
    height: 78px;
    line-height: 78px;
    color: #1890ff;
  }
}
.required span::after {
  left: -20px;
  top: 3px;
}
.filedClear {
  width: 28px;
  height: 28px;
}
.wrap {
  background: #fff;
  // margin: 24px 0;
  padding: 20px;
  width: 100vw;
  .top {
    display: flex;
    justify-content: flex-start;
    .icon {
      width: 6px;
      height: 36px;
      background: #1890ff;
      margin-top: 6px;
      margin-right: 20px;
    }
    .title {
      width: 620px;
      margin-right: 20px;
      font-size: 32px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #191f25;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .title-m {
      margin-left: 0.3rem;
    }
    .spot img {
      width: 40px;
      height: 40px;
    }
  }
  .center {
    p {
      margin: 16px 25px;
      font-size: 28px;
      display: flex;
      position: relative;
      .key {
        color: #888888;
      }
      .value {
        color: #191f25;
        width: 380px;
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
      .arrow {
        color: #1890ff;
        // float: right;
        // margin-right: -0.05rem;
        // display: block;
        position: absolute;
        right: -10px;
      }
    }
    .showAll {
      background: #f5f8ff;
      width: 100vw;
      margin-left: -0.15rem;
      padding: 0.15rem;
      margin-bottom: 0.15rem;
    }
    .fontAno {
      font-size: 30px;
      padding-left: 20px;
    }
  }
  .label {
    margin-left: -0.03rem;
    margin-top: -0.1rem;
    span {
      height: 0.16rem;
      background: #f0f6fe;
      color: #1890ff;
      margin-right: 0.1rem;
      padding: 0.03rem 0.08rem;
      font-size: 0.11rem;
      border-radius: 0.03rem;
    }
  }
  .foot {
    // height: 0.33rem;
    // line-height: 0.33rem;
    display: flex;
    justify-content: space-between;
    // margin: 0.15rem 0.12rem 0 0.12rem;
    font-size: 0.14rem;
    .pictures {
      width: 0.33rem;
      height: 0.33rem;
      line-height: 0.33rem;
      text-align: center;
      color: #fff;
      background: #1890ff;
      display: block;
      border-radius: 0.06rem;
      font-size: 0.12rem;
      margin-right: 0.1rem;
    }
    .text {
      width: 1rem;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .opera {
      color: #1890ff;
      font-size: 0.14rem;
    }
  }
}
.tabs-box-rel {
  position: relative;
  height: 22.51px;
  .tabs-up {
    position: absolute;
    width: 100%;
    background: #fff;
  }
}
.tabs-box {
  .tabs {
    display: flex;
    flex-wrap: wrap;
    .tab {
      width: 25%;
      text-align: center;
      font-size: 0.4rem;
    }
    .tabsAll {
      color: #1890ff;
      z-index: 20;
    }
    .active {
      color: #1890ff;
    }
  }

  .arrow-up-tab {
    color: #1890ff;
    text-align: center;
    font-size: 0.4rem;
  }
}
</style>
